package com.cuzofu.fs.service.impl;

import cn.hutool.core.util.StrUtil;
import com.cuzofu.fs.common.PageUtils;
import com.cuzofu.fs.common.Query;
import com.cuzofu.fs.common.exception.RRException;
import com.cuzofu.fs.vo.BlueprintHistoryVO;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.cuzofu.fs.dao.BlueprintHistoryDao;
import com.cuzofu.fs.entity.BlueprintHistoryEntity;
import com.cuzofu.fs.service.BlueprintHistoryService;


@Service("blueprintHistoryService")
public class BlueprintHistoryServiceImpl extends ServiceImpl<BlueprintHistoryDao, BlueprintHistoryEntity> implements BlueprintHistoryService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<BlueprintHistoryEntity> page = this.page(
                new Query<BlueprintHistoryEntity>().getPage(params),
                new QueryWrapper<BlueprintHistoryEntity>()
        );

        return new PageUtils(page);
    }

    @Override
    public List<BlueprintHistoryVO> listContainsIssue(BlueprintHistoryVO vo) {
        if (StrUtil.isEmpty(vo.getBid())) {
            throw new RRException("缺少必要参数：bid");
        }
        QueryWrapper<BlueprintHistoryVO> qw = new QueryWrapper<>();
        qw.eq("bid", vo.getBid());
        qw.orderByDesc("version");
        return this.baseMapper.queryHistoryList(qw);
    }

}